<template>
  <div :class="className">
    <!-- style -->
    <div v-html="css"></div>
    <!--客服静态-->
    <div class="customer_service">
      <template v-if="datas.style_radio == 1">
        <!-- 样式一 -->
        <template v-if="datas.get_style == '3'">
          <div class="service-item" v-for="(item, index) in datas.list" :key="index">
            <div class="avatar">
              <img :src="item.avatar || emptyImage" alt="" />
            </div>
            <div class="name">{{ item.name }}</div>
            <span class="btn-session">
              <span class="button-item">{{ datas.button_title }}</span>
            </span>
          </div>
        </template>
        <template v-if="!datas.get_style || datas.get_style == '4'">
          <div class="service-item" v-for="(item, index) in 6" :key="index">
            <div class="avatar">
              <img :src="emptyImage" alt="" />
            </div>
            <div class="name">客服昵称</div>
            <span class="btn-session">
              <span class="button-item">{{ datas.button_title }}</span>
            </span>
          </div>
        </template>
      </template>

      <div v-show="datas.style_radio == 2" style="width:100%;">
        <div class="lawyer" v-for="(item, index) in datas.list" :key="index">
          <div class="d-f ">
            <div class="d-f y-l">
              <img :src="item.avatar || emptyImage" alt="" />
            </div>
            <div class="d-f y-r">
              <div class="d-f f-j-c">
                <div class="s-16 name_color" style="">{{ item.name||'客服昵称' }}</div>
                <div class="btn s-10">{{ datas.button_title }}</div>
              </div>
              <div class="d-f" style="flex-wrap: wrap;" v-if="item.tags">
                <div class="job_color tag_1" v-for="(str,i) in item.tags.split(/\s+/)" :key="i">{{str}}</div>
              </div>
              <div class="d-f" style="line-height: 12px;">
                <div class="tag s-10">{{ item.sketch||'---' }}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div style="margin: 0 auto;" v-if="datas.get_style == '3' && (!datas.list || datas.list.length <= 0)">
        <a-empty />
      </div>
    </div>
  </div>
</template>

<script>
import emptyImage from "@/resource/images/image.png";

// 自定义样式
const css = function() {
  if (this.datas.preview_color) {
    const { preview_color, font_size, font_color, button_size, button_bg_color, button_color, show_border, button_border_color,job_color,job_bg } = this.datas;

    return `
				.component-${this.id} .customer_service {
            background-color: ${preview_color.color || "#ffffff"};
            background-image: url(${preview_color.isColor == 2 ? preview_color.image : ""});
            background-size: 100% 100%;
            background-position: center;
            background-repeat: no-repeat;
        }

        .component-${this.id} .customer_service .name {
            font-size: ${font_size}px;
            color: ${font_color};
        }

        .component-${this.id} .customer_service .btn-session {
        		background-color: ${button_bg_color};
            font-size: ${button_size}px;
            color: ${button_color};
            border: solid ${show_border ? "1" : "0"}px ${button_border_color};
        }

				.component-${this.id} .lawyer .job_color {
            color: ${job_color};
            background-color: ${job_bg};
            border-radius: 3px;
        }

				.component-${this.id} .lawyer .name_color {
					font-size: ${font_size}px;
          color: ${font_color};
        }
				.component-${this.id} .lawyer .btn {
            color: ${button_color};
						font-size: ${button_size}px;
            background-color: ${button_bg_color};
            border: solid ${show_border ? "1" : "0"}px ${button_border_color};
        }
    `;
  }
};

export default {
  data() {
    return {
      emptyImage,
      img: require("../../../resource/images/banner.png"),
    };
  },
  props: ["id", "datas", "styles"],
  computed: {
    css() {
      return "<style>" + css.call(this) + "</style>";
    },
    className() {
      const name = ["component-wrapper", `component-${this.id}`];
      return name;
    },
  },

  methods: {},

  mounted() {
    this.$emit("loaded");
  },
};
</script>

<style lang="less" scoped>
.customer_service {
  display: flex;
  flex-flow: wrap;
  padding: 10px 8px 0;
  font-size: 12px;
  color: #333333;

  .service-item {
    display: flex;
    flex: 0 0 30%;
    flex-direction: column;
    justify-content: space-evenly;
    align-items: center;
    padding: 10px 5px;
    background-color: #ffffff;
    border-radius: 10px;
    margin: 0 4px 10px;
  }

  .avatar {
    width: 100px;
    height: 100px;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 10px;

    img {
      width: 100%;
      height: 100%;
    }
  }

  .btn-session {
    color: #3b98f7;
    margin-top: 10px;
    padding: 2px 8px;
    border-radius: 15px;
    background-color: #f5f5f5;
  }
}
  .lawyer{
    margin: 0px 6px 14px 6px;
    box-shadow: 1px 2px 4px rgba(61,61,61,0.25);
    border-radius: 10px;
    padding: 10px;
    font-size: 14px;
		background: #fff;
    .d-f{
      display: flex;
      align-items: center;
    }
    .f-j-c{
      justify-content: space-between;
    }
    .y-l{
      margin-right: 12px;
      img{
        width: 87px;
        height: 87px;
        border-radius: 4px;
        overflow: hidden;
      }
    }
    .y-r{
      flex: 1;
      flex-direction: column;
			height: 87px;
    	justify-content: space-between;
      .d-f{
        width: 100%;
        margin-bottom: 4px;
      }
    }
    .s-16{
      font-size: 16px;
    }
    .s-10{
      font-size: 10px;
    }
    .tag{
      line-height: 16px;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 2;
    }
    .tag_1{
      padding: 0 5px;
      line-height: 18px;
      margin-right: 5px;
      font-size: 12px;
			margin-bottom: 4px;
    }
    .btn{
      padding: 0 6px;
      text-align: center;
      border: 1px solid #1B1B1D;
      border-radius: 10px;
    }
  }
</style>
